package impl.gui;

import impl.core.UDecideManager;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import org.protege.editor.owl.OWLEditorKit;
import org.protege.editor.owl.model.selection.OWLSelectionModelListener;
import org.protege.editor.owl.ui.frame.individual.OWLIndividualFrame;
import org.protege.editor.owl.ui.frame.individual.OWLIndividualPropertyAssertionsFrame;
import org.protege.editor.owl.ui.framelist.OWLFrameList;
import org.protege.editor.owl.ui.framelist.OWLFrameListRenderer;
import org.semanticweb.owlapi.model.OWLNamedIndividual;

public class ChoiceInformationPanel extends JPanel implements OWLSelectionModelListener {

	private OWLFrameList<OWLNamedIndividual>	indiDescriptionList;
	private OWLFrameList<OWLNamedIndividual>	indiPropertyList;

	public ChoiceInformationPanel() {
		OWLEditorKit editorKit = UDecideManager.getInstance().getOWLEditorKit();

		this.indiDescriptionList = new OWLFrameList<OWLNamedIndividual>(editorKit, new OWLIndividualFrame(editorKit));
		this.indiPropertyList = new OWLFrameList<OWLNamedIndividual>(editorKit, new OWLIndividualPropertyAssertionsFrame<OWLNamedIndividual>(editorKit));
		this.indiDescriptionList.setEnabled(false);
		this.indiPropertyList.setEnabled(false);

		OWLFrameListRenderer renderer = new OWLFrameListRenderer(editorKit);
		renderer.setHighlightKeywords(false);
		this.indiPropertyList.setCellRenderer(renderer);

		JSplitPane helpSplitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(this.indiDescriptionList), new JScrollPane(this.indiPropertyList));
		helpSplitter.setDividerSize(2);
		helpSplitter.setResizeWeight(0.5);
		this.setLayout(new BorderLayout());
		this.add(helpSplitter, BorderLayout.CENTER);
		UDecideManager.getInstance().getOwlWorkspace().getOWLSelectionModel().addListener(this);

		UDecideManager.getInstance().addDisposableObject(this);
	}

	@Override
	public void selectionChanged() throws Exception {
		this.indiDescriptionList.setRootObject(UDecideManager.getInstance().getOwlWorkspace().getOWLSelectionModel().getLastSelectedIndividual());
		this.indiPropertyList.setRootObject(UDecideManager.getInstance().getOwlWorkspace().getOWLSelectionModel().getLastSelectedIndividual());
	}

	public void dispose() {
		UDecideManager.getInstance().getOwlWorkspace().getOWLSelectionModel().removeListener(this);
		this.indiDescriptionList.dispose();
		this.indiPropertyList.dispose();
	}

}
